﻿@using System.Data;
@{
    ViewBag.Title = "模板管理";
    DataTable rptCurrent = ViewBag.rptCurrent;
    List<SelectListItem> sitelList = ViewBag.siteListItems;
    int i = 0;
}
@model System.Data.DataTable
<form id="form1" class="layui-form">
    <!--导航栏-->
    <div class="pageheader">
        <div class="page-bar">
            <ul class="page-breadcrumb">
                <li><a href="javascript:history.back(-1);" class="back"><i class="fa fa-mail-reply-all"></i><span>返回上一页</span></a></li>
                <li><a href="javascript:;"><i class="iconfont icon-home1"></i> 首页</a> </li>
                <li><a href="javascript:;">界面管理</a> </li>
                <li><a href="javascript:;">模板管理</a> </li>
            </ul>
        </div>
    </div>
    <!--/导航栏-->
    <!--工具栏-->
    <div class="layui-fluid">
        <div class="layui-card layui-tab">
            <div class="layui-card-body table-tool-mini">
                <div class="layui-form toolbar">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            @foreach (var kv in sitelList)
                            {
                                if (kv.Value == ViewBag.site_id)
                                {
                                    <input type="radio" name="rblSiteId" value="@kv.Value" title="@kv.Text" lay-filter="selectChanged" checked />
                                }
                                else
                                {
                                    <input type="radio" name="rblSiteId" value="@kv.Value" title="@kv.Text" lay-filter="selectChanged" />
                                }
                            }
                        </div>
                    </div>

                </div>
                <div class="template_gird">
                    <div class="current_template">
                        <div class="heading">当前使用模板（templates）</div>
                        <table border="0" cellpadding="0" cellspacing="0">
                            @foreach (DataRow dr in rptCurrent.Rows)
                            {
                                <tr>
                                    <td valign="top">
                                        <div class="template_pic" id="template_pic"><img src="~/templates/@dr["skinname"]/@dr["preview"]" /></div>
                                    </td>
                                    <td valign="top">
                                        <div class="template_info">
                                            <div class="template_foldername">@dr["skinname"]<span class="time">DATE:@dr["createdate"]</span></div>
                                            <div class="template_name pt10">@dr["name"]<span class="demo"><a href="@dr["demo"]" target="_blank" title="查看演示">查看演示</a></span></div>
                                            <div class="template_author">作者：<span class="author"><a href="@dr["website"]" target="_blank" title="访问作者主页">@dr["author"]</a></span></div>
                                            <div class="description">版本：@dr["version"]</div>
                                            <div class="description">描述：@dr["description"]</div>
                                            <div class="action_line">
                                                <input id="hideSkinName_0" type="hidden" value="@dr["skinname"]" />
                                                <!--<a href="javascript:;" onclick="SubmitStart('@dr["skinname"]')" title="一键转化原来的HTML模板" class="layui-btn layui-btn-warm itip">一键转化</a>-->
                                                <a href="../settings/templet_file_list?skin=@dr["skinname"]" title="编辑模板文件" class="layui-btn layui-btn-warm itip">编辑模板文件</a>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            }
                        </table>
                        @if (rptCurrent.Rows.Count == 0)
                        {
                            <div class="nodata">暂无应用模版</div>
                        }
                    </div>

                    <div class="template_list">
                        <div class="heading">其他可用模板</div>
                        @foreach (DataRow dr in Model.Rows)
                        {
                            i++;
                            <div class="template">
                                <div class="template_pic"><img src="~/templates/@dr["skinname"]/@dr["preview"]"></div>
                                <div class="template_foldername">
                                    @dr["skinname"]<span class="time">DATE:@dr["createdate"]</span>
                                </div>
                                <div class="template_name">@dr["name"]<span class="demo"><a href="@dr["demo"]" target="_blank" title="查看演示">查看演示</a></span></div>
                                <div class="template_author">作者：<span class="author"><a href="@dr["website"]" target="_blank" title="查看演示">@dr["author"]</a></span></div>
                                <div class="teplate_version">版本：<span class="version">@dr["version"]</span></div>
                                <div class="description">描述：@dr["description"]</div>
                                <div class="action_line">
                                    <input id="hideSkinName_@i" type="hidden" value="@dr["skinname"]" />
                                    <a href="javascript:;" onclick="SubmitStart('@dr["skinname"]')" id="lbtnStart_@i">启用此模板</a>
                                    |
                                    <a href="../settings/templet_file_list?skin=@dr["skinname"]">编辑模板文件</a>
                                </div>
                            </div>
                        }
                        @if (Model.Rows.Count == 0)
                        {
                            <div class="nodata">暂无其它可应用模版</div>
                        }
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--/工具栏-->
</form>
@section Scripts{
    <script type="text/javascript">
        layui.use(['form'], function () {
            var form = layui.form;

            form.on('radio(selectChanged)', function (data) {
                document.location = "Templet_List?site_id=" + data.value;
            });
        });
        function SubmitStart(skinname) {
            var loadIndex = layer.msg('操作执行中...', { icon: 16, time: false });
            $.ajax({
                url: "TempletListStart?skinname=" + skinname + "&site_id=" +@ViewBag.site_id,
                type: "GET",
                dataType: "json",
                success: function (data) {
                    if (data.status == 1) {
                        layer.msg(data.msg, { icon: 6 });
                        setTimeout(function () {
                            location.reload();
                        }, 1500);
                    } else {
                        layer.alert(data.msg, { icon: 5 });
                    }
                    layer.close(loadIndex);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.close(loadIndex);
                    layer.alert('状态：' + textStatus + '；出错提示：' + errorThrown, { icon: 5 });
                }
            });
        }
        function btnConversion(skinname) {
            var loadIndex = layer.msg('转化中...', { icon: 16, time: false });
            $.ajax({
                url: "templet_conversion?skinname=" + skinname + "&site_id=" +@ViewBag.site_id,
                type: "GET",
                dataType: "json",
                success: function (data) {
                    if (data.status == 1) {
                        layer.msg(data.msg, { icon: 6 });
                    } else {
                        layer.alert(data.msg, { icon: 5 });
                    }
                    layer.close(loadIndex);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.close(loadIndex);
                    layer.alert('状态：' + textStatus + '；出错提示：' + errorThrown, { icon: 5 });
                }
            });
        }
    </script>
}
